import random
import uuid
from Config.RunConfig import RunConfig, Options


class LocationOperations:
    def __init__(self):
        self._operationsList = [
            self._enumerateLocations,
            self._enumerateRegions,
            self._getLocationInfoByName
        ]
        if  RunConfig().get(Options.StressTest.stressAllPartners) == 'True':
             self._operationsList.append(self._addRegion)

        self._baseLocation = {
            'name': uuid.uuid4()
        }
        self._locationsCount = 5

    def _getRandomOperation(self):
        return random.choice(self._operationsList)

    def _createRandomLocation(self, manserv, location):
        self._baseLocation['name'] = uuid.uuid4()
        manserv.AddLocation(**self._baseLocation)

    def _createLocation(self, manserv, location):
        self._baseLocation['name'] = 'Location_' + str(location)
        manserv.AddLocation(**self._baseLocation)

    def _enumerateLocations(self, manserv, location):
        manserv.EnumerateLocations()

    def _enumerateRegions(self, manserv, location):
        manserv.EnumerateRegions()

    def _addRegion(self, manserv, location):
        manserv.AddRegion(id = random.randint(1, 10), name = uuid.uuid4())

    def _getLocationInfoByName(self, manserv, location):
        result = manserv.EnumerateLocations()
        if len(result.locationInfo) > 1:
            resultLenth = random.randint(1, len(result.locationInfo)-1)
            name = result.locationInfo[resultLenth].name
            manserv.GetLocationInfoByName(name = name)
